package stackoverflow.domain.question;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;

import stackoverflow.domain.shared.Entity;
import stackoverflow.domain.shared.IdGenerator;

public class Tag implements Entity<Tag>
{
	private static final long serialVersionUID = 1L;

	private String id= IdGenerator.createId();
	private String name;
	
	public Tag(){}
	public Tag(String name)
	{
		this.name=name; 
	}

	@Override
	public int hashCode()
	{
		return new HashCodeBuilder().append(name).toHashCode();
	}

	@Override
	public boolean equals(Object obj)
	{
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Tag other = (Tag) obj;
		return sameIdentityAs(other);
	}

	public boolean sameIdentityAs(final Tag other)
	{
		return other!=null && new EqualsBuilder().append(this.name, other.name).isEquals();
	}
	
	
}
